import { XObjectName } from '../../object';
import { Statement, STATEMENT_KIND, STATEMENT_TAG } from '../statement';
import { DropBehavior } from './types';

export class DropSequence<N extends string = string> extends Statement {
  static isDropSequence(object: any): object is DropSequence {
    return (
      Statement.isStatement(object) &&
      object.$kind === STATEMENT_KIND.DROP_SEQUENCE
    );
  }
  $kind: STATEMENT_KIND.DROP_SEQUENCE = STATEMENT_KIND.DROP_SEQUENCE;
  $name: XObjectName<N>;
  $behavior: DropBehavior = 'DROP';
  $tag: STATEMENT_TAG.EXECUTABLE = STATEMENT_TAG.EXECUTABLE;

  constructor(name: XObjectName<N>) {
    super();
    this.$name = name;
  }
}

export function DropSequenceBuilder(name: XObjectName): DropSequence {
  return new DropSequence(name);
}

DropSequenceBuilder.ifExists = function (name: XObjectName): DropSequence {
  const statement = DropSequenceBuilder(name);
  statement.$behavior = 'DROP_IF_EXISTS';
  return statement;
};

export type DropSequenceBuilder = typeof DropSequenceBuilder;
